package com.ybwh.springboot1.controller;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.ybwh.springboot1.common.RespData;
import com.ybwh.springboot1.model.po.User;
import com.ybwh.springboot1.model.vo.UserParamVo;
import com.ybwh.springboot1.service.UserService;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户模块控制器
 */
@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;

	@RequestMapping("/userList")
	public ModelAndView userList() {
		ModelAndView mav = new ModelAndView("sys/userList");
		return mav;
	}

	@ResponseBody
	@RequestMapping("/queryUserPage")
	public RespData<PageInfo<User>> queryUserPage(
			@ModelAttribute UserParamVo param,
			@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {

		try {

			return RespData.successResp(userService.queryUserPage(pageNum, pageSize,param));

		} catch (Exception e) {
			log.error("queryUserPage error.", e);
			return RespData.failedResp(ExceptionUtils.getStackTrace(e));
		}

	}
}
